<?php 
	
	class Black_list_model extends CI_Model {
		
		 var $tblName = "blacklist";
		 
		function __construct()
		{
			parent::__construct();
		}
		
		function save($record, $id)
		{
			$id = (int)$id;
			if( $id > 0 ) 
			{
				$this->db->where('id', $id);
				$this->db->update($this->tblName, $record);
			}
			else
			{
				$this->db->insert($this->tblName, $record);
			}
			
			DB_modification_logs("black_list");
		}
		
		function getDetailByID($id)
		{
		  $sql = "SELECT * FROM " . $this->tblName . " WHERE id= " . intval($id);
		  return $this->db->query($sql)->row_array();
		}
		
		function getListingData($GET, $start, $offset = 20)
		{
 			$where = ' WHERE 1=1 ';
			if( isset($GET['blacklist_cli']) && trim($GET['blacklist_cli']) != '' )
			{
				$where  .= " AND blacklist_cli LIKE '%".trim($this->db->escape($GET['blacklist_cli']),"'")."%' ";	
			}
			if( isset($GET['campaign_type']) && trim($GET['campaign_type']) != '' )
			{
				$where  .= " AND campaign_type LIKE '%".trim($this->db->escape($GET['campaign_type']),"'")."%' ";	
			}
			if( isset($GET['active']) && trim($GET['active']) != '' )
			{
				$where  .= " AND active LIKE '%".trim($this->db->escape($GET['campaign_type']),"'")."%' ";	
			}
			
			$LIMIT = "LIMIT $start ,  $offset ";
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . $this->tblName . " {$where} order by id {$LIMIT} ";
			$results = $this->db->query($sql)->result();	
			$total_record = $this->common_model->get_found_rows();
			
			return array('results' => $results, 'total_record' => $total_record);
			
			
			$config['base_url'] = base_url().$controller_base_path;
			$config['total_rows'] = $this->get_found_rows();
			$config['full_tag_open'] = '<p>';
			$config['full_tag_close'] = '</p>';
			$perPage = $config['per_page'];
			$CI->config->set_item('enable_query_strings', TRUE);
			$CI->pagination->initialize($config);
			$data["results"] = $results;
			$data['total_rows'] = $config['total_rows'];
			$data['start'] = $startFrom+1;
			$data['end'] = $startFrom + $config['per_page'];
 			
			
			
			
		}
  }
?>